package com.itheima.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.itheima.tanhua.api.QuestionApi;
import com.itheima.tanhua.domain.Question;
import com.itheima.tanhua.domain.Settings;
import com.itheima.tanhua.dubbo.mappers.QuestionMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class QuestionApiImpl implements QuestionApi {

    @Autowired
    private QuestionMapper questionMapper;

    /**
     * 添加一条新的记录到tb_question
     *
     * @param question
     */
    @Override
    public void save(Question question) {
        questionMapper.insert(question);
    }

    /**
     * 根据用户id查询记录
     *
     * @param id
     * @return
     */
    @Override
    public Question findByUserId(Long id) {
        LambdaQueryWrapper<Question> qw = Wrappers.lambdaQuery(Question.class);
        qw.eq(Question::getUserId, id);
        return questionMapper.selectOne(qw);
    }

    //修改用户设置的默认问题
    @Override
    public void update(Question question) {
        questionMapper.updateById(question);
    }
}